package com.boot4g.admin.module.publish.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.boot4g.admin.module.publish.service.PushVersionService;
import com.boot4g.entity.PushVersionEntity;
import com.boot4g.utils.PageUtils;
import com.boot4g.utils.Query;
import com.boot4g.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 
 * 
 * @author chenjinjie
 * @email guangyaoliangzijie@163.com
 * @date 2018-08-17 10:48:19
 */
@RestController
@RequestMapping("sys/pushversion")
public class PushVersionController {
	@Autowired
	private PushVersionService pushVersionService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	//@RequiresPermissions("pushversion:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

        Page<PushVersionEntity> page = pushVersionService.selectByPage(query.getPagination(),query);

        PageUtils pageUtil = new PageUtils(page.getRecords(), page.getTotal(), query.getLimit(), query.getCurrPage());

		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{rid}")
	//@RequiresPermissions("pushversion:info")
	public R info(@PathVariable("rid") Long rid){
		PushVersionEntity pushVersion = pushVersionService.selectById(rid);
		
		return R.ok().put("pushVersion", pushVersion);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	//@RequiresPermissions("pushversion:save")
	public R save(@RequestBody PushVersionEntity pushVersion){
		pushVersionService.insert(pushVersion);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	//@RequiresPermissions("pushversion:update")
	public R update(@RequestBody PushVersionEntity pushVersion){
		pushVersionService.updateById(pushVersion);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	//@RequiresPermissions("pushversion:delete")
	public R delete(@RequestBody Long[] rids){
		pushVersionService.deleteBatchIds(Arrays.asList(rids));
		
		return R.ok();
	}
	
}
